


clear all
set more off
pause off
set matsize 11000



capture confirm file "Appendix_Results/"
if _rc mkdir "Appendix_Results/"


capture confirm file "Appendix_Results/gphs/"
if _rc mkdir "Appendix_Results/gphs/"



use "Data/Big_Pandemics.dta", clear
gen pandemic=1
drop year
ren endyear year
sort year
merge 1:1 year using "Data/RealRateSince1310.dta"
sort year
replace pandemic=0 if pandemic==.
gen pandemic100k=cond(dead>=100000,pandemic,0)

merge 1:1 year using "Data/sdeaths.dta" , nogen
gen war_deaths = sdeaths
replace sdeaths =0 if sdeaths==.
replace sdeaths= cond(sdeaths>20000,1,0)
sort year


replace W_realUK = log(W_realUK)*100
keep year W_realUK pandemic100k sdeaths 
sort year
reshape long W_real, i(year) j(country) string
sort  year
tsset year
gen gW_real =  d.W_real
sort  year
tsset year





/********** State space specification starts here *************/

constraint 1	[pot]L.pot			= 1		/* Definitional */	
constraint 2	[pot]L.gw			= 1		/* Definitional */
constraint 3	[gw]L.gw			= 1		/* Random walk assumption */
constraint 4	[W_real]pot			= 1		/* Definitional */


cap drop zero								/* generate zero line for figures */
gen zero = 0



/************	 State space equations	 ******************/

sspace		(pot L.pot L.gw, state noconstant noerror)		/// /* Potential Output */
			(gw L.gw, state noconstant)				/// /* Growth of potential */
			(W_real pot, noconstant ),				/// /* Output */
			covstate(identity) constraints(1/4) difficult /*method(kdiffuse)*/ iterate(25)
			
			qui{
			/* Generate smoothed estimates of potential and growth rate */
			predict y_star if e(sample), states smethod(smooth) equation(pot)

			
	

			
			cap drop Zero
			gen Zero=0
			
			gen plotW_real = W_real/100
			gen ploty_star = y_star/100
			
			/**** plot full sample and post-1985 for more detail ****/
			twoway   (tsline plotW_real if year>1311, yaxis(2) lc(blue) lw(normal) ///
			 xlab(1400(200)2000) ) ///
			(tsline ploty_star  if year>1311, yaxis(2) lc(red)  lw(normal) lp(normal) ///
			 xlab(1400(200)2000, labsize(large)) ylab(, angle(0) axis(2) labsize(large) nogrid) xtitle("Year", size(large)) ytitle("Index", axis(2)  size(large)) ) ///
			, title(" ") graphregion(color(white)) plotregion(color(white)) ///
			legend(col(2) order(1 2 ) region(ls(none) col(white)) size(vlarge)  ///
			label(1 "real wages") label(2 "trend of real wages") ring(0) position(11) ) ///
			name(trend1,replace)  nodraw  
			
			
			
			
			

}





graph combine trend1, ///
graphregion(color(white)) scheme(s1color) ///
rows(1) cols(1) imargin(tiny) ysize(4) xsize(8) iscale(0.75) 

graph save   Appendix_Results/gphs/FigureA1a.gph, replace
graph export Appendix_Results/FigureA1a.pdf, replace


